//
//  UIViewConstraintUtil.m
//  smartagent
//
//  Created by apple on 6/9/2017.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "UIViewConstraintUtil.h"

@implementation UIViewConstraintUtil



+ (NSLayoutConstraint *)view:(UIView *)view addHeightConstraint:(CGFloat)height{
    NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:view
                                                                        attribute:NSLayoutAttributeHeight
                                                                        relatedBy:NSLayoutRelationEqual
                                                                           toItem:nil
                                                                        attribute:NSLayoutAttributeNotAnAttribute
                                                                       multiplier:1.0
                                                                         constant:height];
    [view addConstraint:heightConstraint];
    return heightConstraint;
}

+ (NSLayoutConstraint *)view:(UIView *)view addWidthConstraint:(CGFloat)width{
    NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view
                                                                  attribute:NSLayoutAttributeWidth
                                                                  relatedBy:NSLayoutRelationEqual
                                                                     toItem:nil
                                                                  attribute:NSLayoutAttributeNotAnAttribute
                                                                 multiplier:1.0
                                                                   constant:width];
    [view addConstraint:constraint];
    return constraint;
}

+ (NSLayoutConstraint *)addLeadingConstraintWithSuperView:(UIView *)superView subView:(UIView *)subView constant:(CGFloat)constant{
    NSLayoutConstraint *leading = [NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:subView attribute:NSLayoutAttributeLeading multiplier:1.0f constant:constant];
    
    [superView addConstraint:leading];
    return leading;
}

+ (NSLayoutConstraint *)addTrailingConstraintWithSuperView:(UIView *)superView subView:(UIView *)subView constant:(CGFloat)constant{
    NSLayoutConstraint *trailing = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeTrailing multiplier:1.0f constant:constant];
    
    [superView addConstraint:trailing];
    return trailing;
}

+ (NSLayoutConstraint *)addTopConstraintWithSuperView:(UIView *)superView subView:(UIView *)subView constant:(CGFloat)constant{
    NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeTop multiplier:1.0f constant:constant];
    
    [superView addConstraint:top];
    
    return top;
}

+ (NSLayoutConstraint *)addBottomConstraintWithSuperView:(UIView *)superView subView:(UIView *)subView constant:(CGFloat)constant{
    NSLayoutConstraint *bottom = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeBottom multiplier:1.0f constant:constant];
    
    [superView addConstraint:bottom];
    return bottom;
}

+ (NSLayoutConstraint *)addCenterXConstraintWithSuperView:(UIView *)superView subView:(UIView *)subView {
    NSLayoutConstraint *contraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
    return contraint;
}


+ (NSLayoutConstraint *)addCenterYConstraintWithSuperView:(UIView *)superView subView:(UIView *)subView {
    NSLayoutConstraint *contraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];
    return contraint;
}





@end
